<?php
//header('Content-Type: charset=utf-8');
$page = isset ( $_REQUEST["page"] ) ? intval ( $_REQUEST["page"] ) : 1;

$rows_per_page = 20;

$page_start = ( $page - 1 ) * $rows_per_page;
$page_end = $page * $rows_per_page; 

$queryListErrorByIDPr = mysql_query("SELECT tp.IDTest, tp.IDProject, tp.IDEmployee, tp.Title, tp.TextTest, tp.Time, tp.`Status`,e.FullName,tp.`Delete`,
			   (select c.Comment from pr_comment c, employee e 
									 where c.IDEmployee = e.IDEmployee and c.IDTestProject = tp.IDTest order by c.DateComment DESC limit 1) as Comment_C,
			   (select e.FullName from pr_comment c, employee e 
									 where c.IDEmployee = e.IDEmployee and c.IDTestProject = tp.IDTest order by c.DateComment DESC limit 1) as FullName_C
									 
			   FROM pr_testproject tp, employee e WHERE tp.IDProject = '$id' AND e.IDEmployee = tp.IDEmployee 
			   AND tp.`Delete` = 0 ORDER BY IDTest DESC LIMIT $page_start,$rows_per_page ");

$re = mysql_query("SELECT tp.IDTest, tp.IDProject, tp.IDEmployee, tp.Title, tp.TextTest, tp.Time, tp.`Status`,e.FullName,tp.`Delete`
			   		FROM pr_testproject tp, employee e WHERE tp.IDProject = '$id' AND e.IDEmployee = tp.IDEmployee 
			  		 AND tp.`Delete` = 0 ORDER BY IDTest DESC");
$number_of_page = ceil ( mysql_num_rows( $re ) / $rows_per_page ); 


?>
<script type="text/javascript">
function onclickError(idproject,idemp,page){
	var lang = '<?=$_SESSION['lang']?>';
	$.ajax({url:"admin/project/list_error.php?idproject="+idproject+"&idemp="+idemp+"&newlang="+lang+"&page="+page, success:function(result){
		document.getElementById("aaa").innerHTML=result;
        bindEventAfterAjax();
	}});
	
}

function onclickRecycleBin(idproject,idemp,page){
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
		    //alert(xmlhttp.responseText);
	        document.getElementById("aaa").innerHTML=xmlhttp.responseText;
	        bindEventAfterAjax();
	    }
	  }
	var lang = '<?=$_SESSION['lang']?>';
	xmlhttp.open("GET","admin/project/recyclebin.php?idproject="+idproject+"&idemp="+idemp+"&newlang="+lang+"&pages="+page,true);
	xmlhttp.send();
}
function processEmptyError(idproject,idemployee,page,els){
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
		   // alert(xmlhttp.responseText);
	        document.getElementById("aaa").innerHTML=xmlhttp.responseText;
	        bindEventAfterAjax();
	    }
	  }
	var lang = '<?=$_SESSION['lang']?>';
	//alert('vo day hok'+"content-project/process-empty-error.php?idproject="+idproject+"&idemp="+idemployee+"&newlang="+lang);
	//alert('vo day hok');
	xmlhttp.open("GET","content-project/process-empty-error.php?idproject="+idproject+"&idemp="+idemployee+"&newlang="+lang+"&pages="+page,true);
	xmlhttp.send();
}

</script>

<div style="margin-top: 10px; width: 100%;" id="aaa">
		<a class="caption"><?php echo $l_list_error?> </a>
		<div class="divError divinvi" >
			<div class="rf-p divListError">
				<ul>
					<li><span class="linkAction" onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" onclick="onclickError('<?=$id?>','<?=$id_employee?>',1)" >
						<img src="images/list.png" alt="" />
						<span
							style="display: inline-block; width: 100%"><?php echo $l_error?>
						</span> </span></li>
					<li style="left: 150px"><span onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'"  class="linkAction" onclick="onclickRecycleBin('<?=$id?>','<?=$id_employee?>',1)"><img
							src="images/recyclebin_empty.png" alt="" /><span
							style="display: inline-block; width: 100%"><?php echo $l_reclycle?>
						</span> </span></li>
					
				</ul>
			</div>
			
			<div id='ajaxdelete'>
			<table width="100%" class="rf-dt" id="report">
			<?php 
			if (mysql_num_rows( $queryListErrorByIDPr )<=0) {
			?>
			<tr style="background: #f2f9ff" >
				<td colspan="5" style="padding: 10px"><?=$l_list_emplty?></td>
			</tr>
			<?php }else{
			$i = 0;
			while ($row=mysql_fetch_array($queryListErrorByIDPr)){
				$i++;
				$idtestproject = $row[IDTest];
				$idemplTestpro = $row[IDEmployee];
				$prdelete = $row[Delete];
				$titletestpro = $row[Title];
				$contenttestpro = $row[TextTest];
				$fullnames = $row[FullName];
				$time = $row[Time];
				$indexcomment = (($page-1)*20)+$i;
				
				$stringcolortest = substr($row[Title],0,-14);
				$color = substr($row[Title],-6);
				
				
				$stringcolor = substr($row[Comment_C],0,-14);
				$colorcomment = substr($row[Comment_C],-6);
				
				//tag html tranh be giao dien
				$stringcolor = strip_tags($stringcolor);
				?>
				<tr style="background: #f2f9ff" >
					<td class="rf-dt-c"
						style="width: 25px; vertical-align: middle; text-align: center;min-width: 25px"><?php echo $indexcomment;?>
					</td>
					
					<td class="rf-dt-c" 
						style="padding: 7px; vertical-align: middle; width: 50%;">
						<div class="rowMinHeight" align="left" style="width: 97%;">
							<span onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" onclick="showcommanderror(<?=$indexcomment?>,'<?=$idtestproject?>','<?=$id_employee?>','<?=$id?>',0, this);" class="titleError">
							 <a class="bclick" style="color: #424242;cursor:pointer;padding:2px;">
							<?php 
							if(strlen($stringcolortest)==0){?>
								<font color="#6290ff"><?php echo  $titletestpro ?> </font>
							<?php 
							}
							switch ($color){
								case 'B023AB':
									?> <font color="#B023AB"><?php echo  $stringcolortest ?> </font> <?php	break;
								case '424242':
									?> <font color="#424242"><?php echo  $stringcolortest ?> </font> <?php	break;
								case '3DA850':
									?><font color="#3da850"><?php echo  $stringcolortest ?> </font> <?php	break;
								case 'B02323':
									?><font color="#B02323"><?php echo  $stringcolortest ?> </font> <?php	break;
								default:
									?> <font color="#424242"><?php echo  $stringcolortest ?> </font> <?php	break;
															}?> </a> </span>
							<div class="writeBy">
							
								<div align="right" style="width: 99%; float: left;">
								<span><?php 
									switch ($colorcomment){
										case 'B023AB':
											?> <font color="#B023AB"><?php if (strlen($stringcolor)<=20){echo $stringcolor;}else{echo substr($stringcolor, 0,27)."...";};  ?> </font>
											<?php	break;
										case '424242':
											?> <font color="#424242"><?php if (strlen($stringcolor)<=20){echo $stringcolor;}else{echo substr($stringcolor, 0,27)."...";};  ?> </font> <?php	break;
										case '3DA850':
											?><font color="#3da850"><?php if (strlen($stringcolor)<=20){echo $stringcolor;}else{echo substr($stringcolor, 0,27)."...";};  ?> </font> <?php	break;
										case 'B02323':
											?><font color="#B02323"><?php if (strlen($stringcolor)<=20){echo $stringcolor;}else{echo substr($stringcolor, 0,27)."...";};  ?> </font> <?php	break;
										default:
											?> <font color="#424242"><?php if (strlen($stringcolor)<=20){echo $stringcolor;}else{echo substr($stringcolor, 0,27)."...";};  ?> </font> <?php	break;
									}?> </span> <span style="font-weight: bold;"><?php  if ($row[FullName_C]!="") {
echo '('.$row[FullName_C].')';
}?></span>	
								</div>
							</div>
						</div>
					</td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 150px;">
						<?php echo $fullnames?></td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 130px;"><?php echo $time?>
					</td>
					<td class="rf-dt-c" style="vertical-align: middle; width: 140px;"><div
							class="divInButton" style="text-align: center;">
								<span onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" onclick="viewcommanderror(<?=$indexcomment?>,'<?=$idtestproject?>','<?=$id_employee?>','<?=$id?>',0, this);" class="titleError"
								style="width: 60px" class="odd1" >
									<img src="images/p-view.png" alt="<?php echo $l_View?>" /> 
								</span>
								
						</div></td>
				</tr>
				
				
				
				<tr style="background: #f2f9ff; display:none" id="commentprojecthide" >
				</tr>
				
				<?php }}?>
				
				<tr class="trfoot">
	                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="5">
	                        	<div style="text-align: center; width: 100%">
	                            	<span class="rf-ds">
															
															<?php if ( $number_of_page > 1 ) 
															{ 
																if ($page==1)
																	$p=2;
																else if ($page==$number_of_page)
																	$p=$number_of_page-1;
																else $p=$page;
																if($page!=1){?>
																	<a onclick="onclickError('<?=$id?>','<?=$id_employee?>',1" ><span class='button_next'><?php echo "<<<";?></span> </a>
																	<a onclick="onclickError('<?=$id?>','<?=$id_employee?>',<?=($page-1)?>)" ><span class='button_next'><?php echo "<<";?></span> </a>
																<?php  }
																else{
																	echo "<span class='button_next'><<<</span>"; 
																	echo "<span class='button_next'><<</span>";
																}
																for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																		if ($i<=$number_of_page && $i>0)
																		
																			if ($i==$page){
																				echo "<span class='button_next' style='color: #000'><i>".$i."</i></span>"; 
																			}else{
																			?>
																				<a onclick="onclickError('<?=$id?>','<?=$id_employee?>',<?=$i?>)" ><span class="button_next">
																				<?php 
																				echo $i;
																				?>
																				</span> </a>
																			<?php 
																			}
																		?>
																	
																<?php 
																		}
																	
																	if($page!=$number_of_page){ ?>
																		<a onclick="onclickError('<?=$id?>','<?=$id_employee?>',<?=($page+1)?>)"><span class='button_next'><?php echo ">>";?></span> </a>
																		<a onclick="onclickError('<?=$id?>','<?=$id_employee?>',<?=($number_of_page)?>)" ><span class='button_next'><?php echo ">>>";?></span> </a>
																	<?php }
																	else{
																		echo "<span class='button_next'>>></span> ";
																		echo "<span class='button_next'>>>></span> ";
																	}
																}
															
																
																?>
																													
														</span>
														</div>
														</td>
	                    </tr> 
			</table>
			</div>
		</div>
	</div>